package cn.shop.dys.adapter;

import android.content.Context;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by clannad on 2016/4/5.
 */
public class CategoryCommonViewHolder {
    Map<Integer, View> map = null;
    public View convertView;

    public CategoryCommonViewHolder(Context context, View convertView, int itemLayoutResId) {
        map = new HashMap<>();
        if (convertView == null) {
            convertView = View.inflate(context, itemLayoutResId, null);
            convertView.setTag(this);
        }
        this.convertView = convertView;

    }

    public  <T extends View> T getView(int resId, Class<T> clazz) {
        if (map.get(resId) == null) {
            map.put(resId, convertView.findViewById(resId));
        }
        return (T) map.get(resId);
    }

    public TextView getTextView(int resId) {
        TextView tv = getView(resId, TextView.class);
        return tv;
    }

    public ImageView getImageView(int resId) {
        return getView(resId, ImageView.class);
    }

    public GridView getGridView(int resId) {
        return getView(resId, GridView.class);
    }


}
